//
//  BeginViewController.m
//  PosApp
//
//  Created by 刘萍 on 2018/10/15.
//  Copyright © 2018年 李英新. All rights reserved.
//

#import "BeginViewController.h"

@interface BeginViewController ()

@end

@implementation BeginViewController
- (void)initWithXTGuideView:(NSArray *)images
{
    UIScrollView *gui = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, KScreenW, KScreenH)];
    gui.pagingEnabled = YES;
    // 隐藏滑动条
    gui.showsHorizontalScrollIndicator = NO;
    gui.showsVerticalScrollIndicator = NO;
    // 取消反弹
    gui.bounces = NO;
    for (NSInteger i = 0; i < images.count; i ++) {
        [gui addSubview:({
            self.btnEnter = [UIButton buttonWithType:UIButtonTypeCustom];
            self.btnEnter.frame = CGRectMake(KScreenW * i, 0, KScreenW, KScreenH);
            [self.btnEnter setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];;
            self.btnEnter;
        })];
        
        if (i == images.count-1) {
            [self.btnEnter addSubview:({
                UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                [btn setTitle:@"点击进入" forState:UIControlStateNormal];
                btn.frame = CGRectMake(KScreenW * i, KScreenH - 60, 100, 40);
                btn.center = CGPointMake(KScreenW / 2, KScreenH - 60);
                btn.backgroundColor = KRGBColor(230, 230, 230);
                [btn addTarget:self action:@selector(clickEnter) forControlEvents:UIControlEventTouchUpInside];
                btn;
            })];
        }
    }
    gui.contentSize = CGSizeMake(KScreenW * images.count, 0);
    [self.view addSubview:gui];
    
}

+ (instancetype)shareXTGuideVC
{
    static BeginViewController *x = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        x = [[BeginViewController alloc] init];
    });
    return x;
}
- (void)clickEnter
{
    if (self.delegate != nil && [self.delegate respondsToSelector:@selector(click)]) {
        [self.delegate click];
    }
}
- (BOOL)isShow
{
    // 读取版本信息
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *localVersion = [user objectForKey:@"IsFrist"];
    NSString *currentVersion =[[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
    
    if (localVersion == nil || ![currentVersion isEqualToString:localVersion]) {
        [self saveCurrentVersion];
        return YES;
    }else
    {
        return NO;
    }
}
// 保存版本信息
- (void)saveCurrentVersion
{
    NSString *version =[[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:version forKey:@"IsFrist"];
    [user synchronize];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
